package com.jxpanda.spring.module.auth.core.register.strategy;


import com.jxpanda.infrastructure.core.tollkit.ReflectionKit;
import com.jxpanda.spring.module.auth.core.user.OAuth2ReactiveUserDetailsRepository;
import com.jxpanda.spring.module.auth.core.user.OAuth2UserContext;
import org.springframework.security.core.userdetails.UserDetails;
import reactor.core.publisher.Mono;

public interface OAuth2UserDetailsRepositoryReactiveRegisterStrategy extends OAuth2ReactiveRegisterStrategy {

    /**
     * 返回OAuth2ReactiveUserDetailsRepository对象
     */
    OAuth2ReactiveUserDetailsRepository oAuth2ReactiveUserDetailsRepository();

    /**
     * 使用OAuth2ReactiveUserDetailsRepository保存用户信息
     */
    @Override
    default <T extends UserDetails> Mono<T> register(OAuth2UserContext oAuth2UserContext) {
        return oAuth2ReactiveUserDetailsRepository()
                .saveUser(oAuth2UserContext)
                .map(ReflectionKit::cast);
    }

}
